
@Override
public ApiResponse getOrderSettingByMonth(String month) {
    // 获取指定月份的预约设置列表
    List<Map<String, Object>> orderSettingList = ordersettingMapper.findByMonth(month);
    return new ApiResponse(true, "获取预约设置数据成功", orderSettingList);
}

@Override
public void handleFileUpload(MultipartFile excelFile) throws Exception {
    try (Workbook workbook = new XSSFWorkbook(excelFile.getInputStream())) {
        Sheet sheet = workbook.getSheetAt(0);
        if (sheet == null) {
            throw new IllegalArgumentException("Excel 文件内容为空");
        }

        // 处理 Excel 文件内容
        for (Row row : sheet) {
            if (row.getRowNum() == 0) {
                // 跳过表头
                continue;
            }

            // 读取行数据
            Cell idCell = row.getCell(0);
            Cell dateCell = row.getCell(1);
            Cell maxNumberCell = row.getCell(2);
            Cell reservedNumberCell = row.getCell(3);

            if (idCell != null && dateCell != null && maxNumberCell != null) {
                int id = (int) idCell.getNumericCellValue();
                String date = dateCell.getStringCellValue();
                int maxNumber = (int) maxNumberCell.getNumericCellValue();
                int reservedNumber = reservedNumberCell == null ? 0 : (int) reservedNumberCell.getNumericCellValue();

                // 检查数据库中是否存在该记录
                Map<String, Object> existingRecord = ordersettingMapper.findByOrderDate(date);
                if (existingRecord == null) {
                    // 如果不存在，则插入新记录
                    ordersettingMapper.insertOrderSetting(date, maxNumber, reservedNumber);
                } else {
                    // 如果存在，则更新记录
                    ordersettingMapper.updateOrderSetting(date, maxNumber, reservedNumber);
                }

                System.out.println("ID: " + id + ", Date: " + date + ", Max Number: " + maxNumber + ", Reserved Number: " + reservedNumber);
            }
        }
    }

}

// 新增: 根据 orderDate 查询单条记录
private Map<String, Object> findByOrderDate(String orderDate) {
    return ordersettingMapper.findByOrderDate(orderDate);
}

// 新增: 更新预约设置信息
private void updateOrderSetting(String orderDate, int number, int reservedNumber) {
    ordersettingMapper.updateOrderSetting(orderDate, number, reservedNumber);
}
